<script>
import {ElMessage} from "element-plus";
import axios  from "axios";
export default {
  data() {
    return {
      //分页
      currentPage: 1,
      pageSize: 5,
      pageInfo: {},

      formLabelWidth: '200px',
      queryFrm: {                    // 分享帖标题查询对象
        Share_title: "",
      },
      formShow:{},    //显示建议信息
      formUpdate:{},  // 新增建议信息对象
      adviseData: [], // 建议信息列表
      dialogInsertFormVisible:false,
    }
  },
  methods:{
    //分页
    LoadStuPageData() {
      this.$http.get("http://localhost:8080/advise/page", {
        params: {
          page: this.currentPage,
          size: this.pageSize
        }
      }).then((res) => {
        this.pageInfo = res.data;
        this.tableData = res.data.list;
        console.log(this.tableData);
      }).catch((err) => {
        console.log(err);
      });
    },

    btnDel(Advice_id){
      console.log(Advice_id);
      this.$http.get("http://localhost:8080/advise/del/"+Advice_id).then((res)=>{
        console.log(res.data);
        if (res.data===1){
          console.log("删除成功!");
          ElMessage({
            message: '删除成功!',
            type: 'success',
          })
          this.LoadInsertInfoData();
        }else {
          ElMessage({
            message: '删除失败!',
            type: 'warning',
          })
          console.log("删除失败!");
        }
      }).catch((err)=>{})
    },
    btnInsertAdvise(){            // 打开修改对话框,并回显数据
      this.formUpdate.operator = this.currentAdminName;
      console.log(this.formUpdate.operator)
      this.dialogInsertFormVisible = true;
    },
    btnInsertAdviseInfo(){               // 提交修改以后得数据
      console.log(this.formUpdate);
      this.$http.post("http://localhost:8080/advise/insert",this.formUpdate).then((res)=>{
        if (res.data===1){
          console.log("修改成功!");
          ElMessage({
            message: '修改成功!',
            type: 'success',
          })
          this.LoadInsertInfoData();
          this.formUpdate={};
          this.dialogInsertFormVisible = false;
        }else {
          console.log("修改失败!");
          ElMessage({
            message: '修改失败!',
            type: 'warning',
          })
        }
      }).catch((err)=>{})
    },
    onSubmit(){
      console.log(this.queryFrm);
      this.LoadInsertData();
    },
    LoadInsertData(){
      this.$http.get("http://localhost:8080/advise/queryadvise",{params:{
          Advise_id:this.queryFrm.Advise_id,
        }}).then((res)=>{
        this.adviseData = res.data;
        console.log(res.data);
      }).catch(function(err){
        console.log(err);
      })
    },
    LoadInsertInfoData(){
      this.$http.get("http://localhost:8080/advise/queryall").then((res)=>{
        this.adviseData = res.data;
        console.log(res.data)
      }).catch(function (err){
        console.log(err);
      })
    },
  },
  mounted() {
    this.LoadStuPageData();  //分页
    this.currentAdminName = localStorage.getItem('adminName')
    console.log(this.currentAdminName)
    this.LoadInsertInfoData();
  }
}
</script>

<template>
  <el-card style="max-width: 100%">
    <template #header>
      <div class="card-header">
        <span>建议管理</span>
      </div>
    </template>
    <el-form :inline="true" :model="queryFrm" class="demo-form-inline">
      <el-form-item label="历史建议查询">
        <el-input v-model="queryFrm.Advise_id" placeholder="查询" clearable />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">查询</el-button>
      </el-form-item>
      <el-form-item>
        <el-button type="success" @click="btnInsertAdvise">新增</el-button>
      </el-form-item>
    </el-form>

    <el-table :data="adviseData" stripe style="width: 100%">
      <el-table-column  label="建议编号" prop="advice_id" width="150" />
      <el-table-column prop="advice_man" label="建议人" />
      <el-table-column prop="advice_content" label="建议内容" width="240" />
      <el-table-column prop="advice_time" label="建议时间" />
      <el-table-column prop="advice_phone" label="建议人联系方式" />
      <el-table-column prop="operator" label="操作人" />
      <el-table-column fixed="right" label="操作" width="180">
        <template #default="scope">
          <el-popconfirm
              confirm-button-text="是的"
              cancel-button-text="取消"
              icon-color="#626AEF"
              title="确定要删除这个申诉单吗?"
              @confirm="btnDel(scope.row.advice_id)"
          >
            <template #reference>
              <el-button  type="danger" size="small" >
                删除
              </el-button>
            </template>
          </el-popconfirm>
        </template>
      </el-table-column>
    </el-table>
  </el-card>
  <el-dialog v-model="dialogInsertFormVisible" title="输入建议" width="1000">
    <el-form :model="formUpdate">
      <el-form-item label="建议编号" :label-width="formLabelWidth">
        <el-input v-model="formUpdate.advise_id" autocomplete="off" />
      </el-form-item>
      <el-form-item label="建议人" :label-width="formLabelWidth">
        <el-input v-model="formUpdate.advice_man" autocomplete="off" />
      </el-form-item>
      <el-form-item label="建议内容" :label-width="formLabelWidth">
        <el-input v-model="formUpdate.advice_content" autocomplete="off" />
      </el-form-item>
      <el-form-item label="建议时间" :label-width="formLabelWidth">
        <el-input v-model="formUpdate.advice_time" autocomplete="off" />
      </el-form-item>
      <el-form-item label="建议人联系方式" :label-width="formLabelWidth">
        <el-input v-model="formUpdate.advice_contact" autocomplete="off" />
      </el-form-item>
      <el-form-item label="操作人" :label-width="formLabelWidth">
        {{formUpdate.operator}}
      </el-form-item>
    </el-form>
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="dialogInsertFormVisible = false">取消</el-button>
        <el-button type="primary" @click="btnInsertAdviseInfo">
          新增
        </el-button>
      </div>
    </template>
  </el-dialog>

  <el-pagination
      v-model:current-page="currentPage"
      v-model:page-size="pageSize"
      :page-sizes="[3, 4, 5, 6]"
      layout="total, sizes, prev, pager, next, jumper"
      :total="pageInfo.total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
  />

</template>

<style scoped>
.share-image {
  width: 100px;        /* 或者使用 max-width 来适应容器宽度 */
  height: auto;        /* 保持图片的宽高比 */
  border: 1px solid #ddd; /* 给图片添加边框，便于看出图片范围 */
}
</style>